package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.baomidou.springboot.common.SortEnum;
import com.baomidou.springboot.entity.About;
import com.baomidou.springboot.mapper.AboutMapper;
import com.baomidou.springboot.service.AboutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 关于我们 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class AboutServiceImpl implements AboutService {

    @Autowired
    private AboutMapper aboutMapper;

    @Override
    public void save(About about) {
        about.setCreateDate(new Date());
        aboutMapper.insert(about);
    }

    @Override
    public void delete(String id) {
        aboutMapper.deleteById(id);
    }

    @Override
    public About edit(String id) {
        return aboutMapper.selectById(id);
    }

    @Override
    public void update(About about) {
        about.setModifyDate(new Date());
        aboutMapper.updateById(about);
    }

    @Override
    public About view(String id) {
        return aboutMapper.selectById(id);
    }

    @Override
    public Page<About> list(Page<About> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<About> aboutList = aboutMapper.findByDateDesc(page, search);
        page.setRecords(aboutList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        aboutMapper.deleteBatchIds(ids);
    }

    @Override
    public List<About> findBySort(SortEnum sortEnum) {
        return aboutMapper.findBySort(sortEnum.name());
    }

    @Override
    public About findOneBySort(SortEnum sortEnum) {
        return aboutMapper.findOneBySort(sortEnum.name());
    }

    @Override
    public About findById(String id) {
        return aboutMapper.selectById(id);
    }
}
